package com.sunwayworld.basemodule.basedata.purchase.resource.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.sunwayworld.basemodule.basedata.purchase.resource.LimsPurchaseResource;
import com.sunwayworld.basemodule.basedata.purchase.service.LimsPurchaseService;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import com.sunwayworld.framework.data.page.Page;
import org.springframework.web.bind.annotation.PathVariable;
import com.sunwayworld.basemodule.basedata.purchase.bean.LimsPurchaseMaterialBean;
import com.sunwayworld.framework.log.annotation.Log;
import com.sunwayworld.framework.log.annotation.LogModule;
import com.sunwayworld.framework.log.annotation.LogType;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;

@LogModule("采购")
@RestController
@GikamBean
public class LimsPurchaseResourceImpl implements LimsPurchaseResource {

    @Autowired
    private LimsPurchaseService limsPurchaseService;

    @Override
    public LimsPurchaseService getService() {
        return limsPurchaseService;
    }

    @Log(value = "新增采购", type = LogType.INSERT)
    @Override
    @RequestMapping(method = RequestMethod.POST)
    public Long insert(RestJsonWrapperBean wrapper) {
        return getService().insert(wrapper);
    }

    @Override
    @Log(value = "根据采购ID查询物资", type = LogType.SELECT)
    @RequestMapping(value = "/{id}/materials/queries", method = RequestMethod.POST)
    public Page<LimsPurchaseMaterialBean> selectMaterialPaginationByPurchaseId(@PathVariable Long id, RestJsonWrapperBean wrapper) {
        return getService().selectMaterialPaginationByPurchaseId(id, wrapper);
    }

    @Override
    @Log(value = "新增物资", type = LogType.INSERT)
    @RequestMapping(value = "/{id}/materials", method = RequestMethod.POST)
    public Long insertMaterial(@PathVariable Long id, RestJsonWrapperBean wrapper) {
        return getService().insertMaterial(id, wrapper);
    }

    @Override
    @Log(value = "删除物资", type = LogType.DELETE)
    @RequestMapping(value = "/{id}/materials", method = RequestMethod.DELETE)
    public void deleteMaterial(@PathVariable Long id, RestJsonWrapperBean wrapper) {
        getService().deleteMaterial(id, wrapper);
    }

}
